@file:Suppress("unused")

package top.saplf.sileny.util

import android.content.res.Resources
import android.util.DisplayMetrics
import top.saplf.sileny.SilenyApplication

/**
 * @author Saplf on 17/3/4
 */
val resources: Resources by lazy { SilenyApplication.app.resources }
private val displayMetrics: DisplayMetrics by lazy { resources.displayMetrics }
val displayHeight by lazy { displayMetrics.heightPixels }
val displayWidth by lazy { displayMetrics.widthPixels }
val statusBarHeight by lazy {
    val resourceId = resources.getIdentifier("status_bar_height", "dimen", "android")
    resources.getDimensionPixelSize(resourceId)
}
val navigationShow by lazy {
    val resourceId = resources.getIdentifier("config_showNavigationBar", "bool", "android")
    resources.getBoolean(resourceId)
}
val navigationBarHeight by lazy {
    val resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android")
    resources.getDimensionPixelSize(resourceId)
}

fun Float.dp2px(): Float = this * displayMetrics.density + .5f
fun Int.dp2px(): Float = this.toFloat().dp2px()

fun Float.px2dp(): Float = this / displayMetrics.density + .5f
fun Int.px2dp(): Float = this.toFloat().px2dp()

fun Float.sp2px(): Float = this * displayMetrics.scaledDensity + .5f
fun Int.sp2px(): Float = this.toFloat().sp2px()

fun Float.px2sp(): Float = this / displayMetrics.scaledDensity + .5f
fun Int.px2sp(): Float = this.toFloat().px2sp()
